package com.qsmx.store.app.main.mem;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;
import android.widget.TextView;

import com.qsmx.store.app.R;
import com.qsmx.store.app.R2;
import com.qsmx.store.app.main.adapter.TabPagerAdapter;
import com.qsmx.store.app.main.home.HomeDelegate;
import com.qsmx.store.core.delegates.AtmosDelegate;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MemSaleCardDelegate extends AtmosDelegate {

    String[] titles = new String[]{"售卡", "取消售卡"};

    @BindView(R2.id.tl_mem_card)
    TabLayout tlMemCard = null;
    @BindView(R2.id.vp_mem_card_sale)
    ViewPager vpMemCardSale = null;

    @OnClick(R2.id.iv_back)
    void onBack() {
        getParentDelegate().getSupportDelegate().pop();
    }

    @OnClick(R2.id.iv_home)
    void onHome() {
        getParentDelegate().getSupportDelegate().popTo(HomeDelegate.class, false);
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_mem_sale_card;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        initTab();

    }

    private void initTab() {

        List<Fragment> fragmentList = new ArrayList<>();

        MemSaleCardChildDelegate delegate = new MemSaleCardChildDelegate();
        MemSaleCardBackDelegate delegate1 = new MemSaleCardBackDelegate();

        fragmentList.add(delegate);
        fragmentList.add(delegate1);

        TabPagerAdapter tabPagerAdapter = new TabPagerAdapter(getChildFragmentManager(), fragmentList, titles);
        vpMemCardSale.setAdapter(tabPagerAdapter);
        vpMemCardSale.setOffscreenPageLimit(0);
        tlMemCard.setupWithViewPager(vpMemCardSale);
    }

}
